package com.example.pkmedical.Activity.warning;

import android.os.Bundle;
import android.widget.Button;

import com.example.pkmedical.Base.BaseActivity;
import com.example.pkmedical.R;
import com.example.pkmedical.Utils.CommandUtil;
import com.example.pkmedical.Utils.SPUtils;
import com.example.pkmedical.Utils.SerialProtUtil;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;

public class BedPosLockActivity extends BaseActivity {

    @BindView(R.id.bed_position_lock_goback)
    Button bedPositionLockGoback;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bedposlock);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        TimeCount();
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void showDialog(String... msg) {

    }
    private Disposable mTimeCountDisposable;
    private int timeLong = 5;
    /**
     * 倒计时
     */
    public void TimeCount() {

        if (mTimeCountDisposable != null) {
            //取消上一次的订阅
            mTimeCountDisposable.dispose();
        }
//        //0-count依次输出，延时0s执行，每1s发射一次。
        mTimeCountDisposable = Flowable.intervalRange(0, timeLong, 0, 1, TimeUnit.SECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(aLong -> {

                })
                .doOnComplete(() -> {
                    if (mTimeCountDisposable != null)
                        mTimeCountDisposable.dispose();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            BedPosLockActivity.this.finish();
                        }
                    });

                })
                .subscribe();
    }
    @OnClick(R.id.bed_position_lock_goback)
    public void onViewClicked() {
        finish();
    }
}
